<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">公告管理</ui:define>
    <ui:define name="content">
        <h:form>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>

                        <p:columnToggler datasource="announcementDataTable" trigger="toggler"
                                         rendered="#{security:areAllGranted('DICTIONARY_SEARCH')}"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         rendered="#{announcementListBean.isNormal() and security:areAllGranted('DICTIONARY_SEARCH')}"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{announcementListBean.onReset}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{announcementListBean.isNormal() and security:areAllGranted('DICTIONARY_SEARCH')}"/>
                        <p:commandButton icon="fa fa-plus" value="新增"
                                         action="#{announcementListBean.onAdd}"
                                         rendered="#{announcementListBean.isNormal() and security:areAllGranted('DICTIONARY_ADD')}">
                            <f:setPropertyActionListener value="/views/system/announcement/list.xhtml"
                                                         target="#{currentUserBean.back}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">

                                <p:outputLabel value="公告标题"/>
                                <p:inputText value="#{announcementListBean.$.title}"/>

                                <p:outputLabel value="公告内容"/>
                                <p:inputText value="#{announcementListBean.$.content}"/>

                                <p:outputLabel value="开始时间"/>
                                <p:calendar value="#{announcementListBean.$.startTime}"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATETIME_FORMAT')}"
                                            readonlyInput="true"/>

                                <p:outputLabel value="结束时间"/>
                                <p:calendar value="#{announcementListBean.$.endTime}"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATETIME_FORMAT')}"
                                            readonlyInput="true"/>

                                <p:outputLabel for="sendEmail" value="是否发送邮件"/>
                                <p:selectOneMenu id="sendEmail" value="#{announcementListBean.$.sendEmail}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="是" itemValue="true"/>
                                    <f:selectItem itemLabel="否" itemValue="false"/>
                                </p:selectOneMenu>

                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="announcementDataTable"
                                         style="width: 100%"
                                         var="announcement"
                                         value="#{announcementListBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         resizableColumns="true">

                                <p:column headerText="操作">
                                    <p:splitButton icon="fa fa-eye"
                                                   action="#{announcementListBean.onEdit(announcement.id)}"
                                                   process="@this">
                                        <f:setPropertyActionListener
                                                value="/views/system/announcement/list.xhtml"
                                                target="#{currentUserBean.back}"/>
                                    </p:splitButton>
                                </p:column>
                                <p:column headerText="标题">
                                    <h:outputText value="#{announcement.title}"/>
                                </p:column>
                                <p:column headerText="内容">
                                    <h:outputText value="#{announcement.content}"/>
                                </p:column>
                                <p:column headerText="是否发送邮件">
                                    <h:outputText value="#{announcement.sendEmail ? '是' : '否'}"/>
                                </p:column>
                                <p:column headerText="开始时间">
                                    <h:outputText value="#{announcement.startTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="结束时间">
                                    <h:outputText value="#{announcement.endTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
